package com.csx.governance.traffic.core.context;

/**
 * @author cuisongxu
 * @date 2023/3/18 19:11
 */
public class TrafficContext {

    private TrafficRequest request;

    private TrafficResponse response;

    /**
     * 出口子请求
     */
    private TrafficRequest subRequest;

    /**
     * 出口子响应
     */
    private TrafficResponse subResponse;

    public TrafficContext(TrafficRequest request, TrafficResponse response) {
        this.request = request;
        this.response = response;
    }

    public TrafficRequest getRequest() {
        return request;
    }

    public TrafficResponse getResponse() {
        return response;
    }

    public TrafficRequest getSubRequest() {
        return subRequest;
    }

    public TrafficResponse getSubResponse() {
        return subResponse;
    }

    public TrafficContext setRequest(TrafficRequest request) {
        this.request = request;
        return this;
    }

    public TrafficContext setResponse(TrafficResponse response) {
        this.response = response;
        return this;
    }

    public TrafficContext setSubRequest(TrafficRequest subRequest) {
        this.subRequest = subRequest;
        return this;
    }

    public TrafficContext setSubResponse(TrafficResponse subResponse) {
        this.subResponse = subResponse;
        return this;
    }

    public TrafficContext setAttribute(String key, Object value) {
        getRequest().setAttribute(key, value);
        return this;
    }

    public Object getAttribute(String key) {
        return getRequest().getAttribute(key);
    }
}
